<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // this 关键字
      // this 谁调用我，this就指向谁（es6箭头函数）

      // 全局
      function test() {
        console.log(this) // window
      }
      test()

      setTimeout(() => {
        console.log(this) // window
      }, 2000)

      // 对象
      var obj = {
        name: 'cxm',
        test: function () {
          console.log(this) //{name: 'cxm', test: ƒ}
        },
      }
      obj.test()
    </script>
  </body>
</html>
